package org.oslims.client.uicomponents.editbox;

import org.oslims.client.uicomponents.StyleableFlexTable;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class SearchSamplesBox {

	final DialogBox dialogBox = new DialogBox(false, true);
	final VerticalPanel dialogBoxPanel = new VerticalPanel();
	final ScrollPanel scrollPanel = new ScrollPanel();

	final TextBox codeBox = new TextBox();
	final TextBox descriptionBox = new TextBox();
	final TextBox originBox = new TextBox();
	final TextBox requestBox = new TextBox();
	final TextBox sampleTypeBox = new TextBox();
	final TextBox storagePlaceBox = new TextBox();

	final StyleableFlexTable searchTable = new StyleableFlexTable();

	final Button searchButton = new Button("Search");

	final HorizontalPanel buttonLine = new HorizontalPanel();
	final Button okButton = new Button("Import selected");
	final Button cancelButton = new Button("Cancel");

	public SearchSamplesBox() {
		dialogBox.setText("Search Samples");

		searchTable.setText(0, 1, "Sample Code");
		searchTable.setText(0, 2, "Description");
		searchTable.setText(0, 3, "Origin");
		searchTable.setText(0, 4, "Request Code");
		searchTable.setText(0, 5, "Sample Type");
		searchTable.setText(0, 6, "Storage Place");

		searchTable.setWidget(1, 1, codeBox);
		searchTable.setWidget(1, 2, descriptionBox);
		searchTable.setWidget(1, 3, originBox);
		searchTable.setWidget(1, 4, requestBox);
		searchTable.setWidget(1, 5, sampleTypeBox);
		searchTable.setWidget(1, 6, storagePlaceBox);
		searchTable.setWidget(1, 7, searchButton);

		scrollPanel.add(searchTable);

		scrollPanel.setHeight("500px");
		dialogBoxPanel.add(scrollPanel);

		buttonLine.add(okButton);
		buttonLine.add(cancelButton);
		dialogBoxPanel.add(buttonLine);

		dialogBox.add(dialogBoxPanel);
	}

	public void show() {
		codeBox.setValue("");
		descriptionBox.setValue("");
		originBox.setValue("");
		requestBox.setValue("");
		sampleTypeBox.setValue("");
		storagePlaceBox.setValue("");

		while (searchTable.getRowCount() > 2)
			searchTable.removeRow(2);

		dialogBox.center();
	}

	public void hide() {
		dialogBox.hide();
	}

	public HasValue<String> getCodeBox() {
		return codeBox;
	}

	public HasValue<String> getDescriptionBox() {
		return descriptionBox;
	}

	public HasValue<String> getOriginBox() {
		return originBox;
	}

	public HasValue<String> getRequestBox() {
		return requestBox;
	}

	public HasValue<String> getSampleTypeBox() {
		return sampleTypeBox;
	}

	public HasValue<String> getStoragePlaceBox() {
		return storagePlaceBox;
	}

	public StyleableFlexTable getSearchTable() {
		return searchTable;
	}

	public HasClickHandlers getSearchButton() {
		return searchButton;
	}

	public HasClickHandlers getOkButton() {
		return okButton;
	}

	public HasClickHandlers getCancelButton() {
		return cancelButton;
	}
}
